<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__ROOT__/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__ROOT__/layui/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__ROOT__/layui/css/public.css" media="all">
    <style type="text/css">
        .layui-table-cell {
            height: auto;
            /*overflow:visible; text-overflow:inherit; white-space:normal;*/
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">技术标签</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tag" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">项目内容关键词</label>
                            <div class="layui-input-inline">
                                <input type="text" name="content" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>



        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
<!--        操作栏-->
        <script type="text/html" id="currentTableBar">

            <a class="layui-btn  layui-btn-xs data-count-see " target="_self" href="{:url('documentation/edit')}?id={{d.id}}" data-status="1"><i class="layui-icon layui-icon-edit"></i> </a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete " lay-event="delete"><i class="layui-icon layui-icon-close-fill"></i></a>

        </script>
<!--        封面图片-->
        <script type="text/html" id="show_img">
          <img src="{{d.img}}" style="width: 50px">
        </script>
<!--    附件按钮    -->
        <script type="text/html" id="fujian">
            <i class="layui-icon layui-icon-export" lay-event="fujian" style="font-size: 30px"></i>
        </script>
    </div>
</div>
<script src="__ROOT__/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>



<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/index.php/index/documentation/get_list',
            cols: [[
                {field: '', width:80, title: '序号', type:'numbers'},
                {field: 'title',width:200, title: '项目名称'},
                {field: '',width:100, title: '封面图片',templet:'#show_img'},
                {field: 'tag',width:200, title: '技术标签'},
                {field: '',  title: '附件',width:60,templet:'#fujian'},
                {field: 'content',  title: '项目内容'},

                {field: 'see',width:100, title: '总浏览数'},
                {field: 'love',width:100, title: '总喜欢数'},
                {title: '操作',width:100, toolbar: '#currentTableBar', align: "left" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 20,
            page: true,
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);


            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */


        table.on('tool(currentTableFilter)', function (obj) {
            var mdata = obj.data;

           if (obj.event === 'delete') {
                layer.confirm('真的要删除案例吗', function (index) {
                    var url = "{:url('documentation/del')}";
                    var data={'id':mdata.id};
                    var success = "{:url('documentation/index')}";
                    //    执行异步请求 ，$.post
                    $.post(url,data,function(result){
                        if(result.status ==0){
                            layer.open({
                                content:result.message,
                                icon:2,
                                title : '错误提示'
                            });

                        }
                        if(result.status ==1){
                            layer.open({
                                content : result.message,
                                icon : 1,
                                yes : function(){
                                    location.href=success;
                                }
                            });

                        }
                    },'JSON');
                    return false;
                });
            }

            else if (obj.event === 'see') {
                var index = layer.open({
                    title: '订单详情',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['60%', '80%'],
                    content: '/index.php/index/order/see?id='+mdata.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
           else if (obj.event === 'fujian') {
               var index = layer.open({
                   title: '附件详情',
                   type: 2,
                   shade: 0.2,
                   maxmin:true,
                   shadeClose: true,
                   area: ['60%', '80%'],
                   content: '/index/documentation/open_file?id='+mdata.id,
               });
               $(window).on("resize", function () {
                   layer.full(index);
               });
               return false;
           }
        });


    });
</script>


</body>
</html>